package com.gaojun;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.text.Font;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * 启动项
 * @author gj
 *
 */
public class MultimediaProcessingMain extends Application {

	private double xOffset = 0;
	private double yOffset = 0;

	@Override
	public void start(Stage primaryStage) throws Exception {
		// TODO Auto-generated method stub
		String style = "-fx-background-color:#00000000";
		String styleEntered = "-fx-background-color:#802a2a";
		Pane pane = new Pane();
		pane.setPrefSize(800, 430);
		pane.setStyle("-fx-background-color:#292421");
		Button btnClose = new Button("");
		btnClose.setGraphic(new ImageView(new Image("res/image/stage/closestage.png")));
		btnClose.setLayoutX(760);
		btnClose.setLayoutY(2);
		btnClose.setStyle(style);
		btnClose.setOnMouseEntered(e -> {
			btnClose.setStyle(styleEntered);
		});

		btnClose.setOnMouseExited(e -> {
			btnClose.setStyle(style);
		});

		btnClose.setOnMouseClicked(e -> {
			primaryStage.close();
		});
		Button btnHide = new Button("");
		btnHide.setGraphic(new ImageView(new Image("res/image/stage/hide.png")));
		btnHide.setLayoutX(730);
		btnHide.setLayoutY(2);
		btnHide.setStyle(style);
		btnHide.setOnMouseEntered(e -> {
			btnHide.setStyle(styleEntered);
		});

		btnHide.setOnMouseExited(e -> {
			btnHide.setStyle(style);
		});

		btnHide.setOnMouseClicked(e -> {
			primaryStage.setIconified(true); // 将窗体隐藏到图标
		});

		Line line = new Line();
		line.setStartX(0);
		line.setStartY(30);
		line.setEndX(800);
		line.setEndY(30);
		line.setFill(Color.WHITE);
		line.setStroke(Color.WHITE);
		line.setStrokeWidth(0.2);

		Pane btnRecordVideo = new Pane();
		ImageView recordVideoimageView = new ImageView(new Image("res/image/stage/recordvideo.png"));
		recordVideoimageView.setLayoutX(25);
		btnRecordVideo.setLayoutX(20);
		btnRecordVideo.setLayoutY(130);
		btnRecordVideo.setStyle(style);
		btnRecordVideo.setPrefSize(180, 165);

		Label lblRecordVideo = new Label("录  屏");
		lblRecordVideo.setTextFill(Color.WHITE);
		lblRecordVideo.setFont(Font.font("KaiTi", 28));
		lblRecordVideo.setLayoutX(45);
		lblRecordVideo.setLayoutY(125);

		btnRecordVideo.getChildren().add(recordVideoimageView);
		btnRecordVideo.getChildren().add(lblRecordVideo);

		btnRecordVideo.setOnMouseEntered(e -> {
			btnRecordVideo.setStyle("-fx-border-color:#fff;-fx-border-width:1px");
		});

		btnRecordVideo.setOnMouseExited(e -> {
			btnRecordVideo.setStyle("-fx-border-width:0px");
		});
		btnRecordVideo.setOnMouseClicked(e -> {
			VideoScreenRecording videoScreenRecording = new VideoScreenRecording();
			videoScreenRecording.show();
			primaryStage.close();
		});

		Pane btnRecordAudio = new Pane();
		ImageView recordAudioimageView = new ImageView(new Image("res/image/stage/audio.png"));
		recordAudioimageView.setLayoutX(25);
		btnRecordAudio.setLayoutX(220);
		btnRecordAudio.setLayoutY(130);
		btnRecordAudio.setStyle(style);
		btnRecordAudio.setPrefSize(180, 165);

		Label lblRecordAudio = new Label("录  音");
		lblRecordAudio.setTextFill(Color.WHITE);
		lblRecordAudio.setFont(Font.font("KaiTi", 28));
		lblRecordAudio.setLayoutX(45);
		lblRecordAudio.setLayoutY(125);

		btnRecordAudio.getChildren().add(recordAudioimageView);
		btnRecordAudio.getChildren().add(lblRecordAudio);

		btnRecordAudio.setOnMouseEntered(e -> {
			btnRecordAudio.setStyle("-fx-border-color:#fff;-fx-border-width:1px");
		});

		btnRecordAudio.setOnMouseExited(e -> {
			btnRecordAudio.setStyle("-fx-border-width:0px");
		});

		btnRecordAudio.setOnMouseClicked(e -> {
			AudioRecording audioRecording = new AudioRecording();
			audioRecording.show();
			primaryStage.close();
		});

		Pane btnChangeType = new Pane();
		ImageView changeTypeimageView = new ImageView(new Image("res/image/stage/changetype.png"));
		changeTypeimageView.setLayoutX(0);
		btnChangeType.setLayoutX(400);
		btnChangeType.setLayoutY(130);
		btnChangeType.setStyle(style);
		btnChangeType.setPrefSize(180, 165);

		Label lblChangeType = new Label("转换格式");
		lblChangeType.setTextFill(Color.WHITE);
		lblChangeType.setFont(Font.font("KaiTi", 28));
		lblChangeType.setLayoutX(35);
		lblChangeType.setLayoutY(125);

		btnChangeType.getChildren().add(changeTypeimageView);
		btnChangeType.getChildren().add(lblChangeType);

		btnChangeType.setOnMouseEntered(e -> {
			btnChangeType.setStyle("-fx-border-color:#fff;-fx-border-width:1px");
		});

		btnChangeType.setOnMouseExited(e -> {
			btnChangeType.setStyle("-fx-border-width:0px");
		});
		btnChangeType.setOnMouseClicked(e -> {
			ChangeVideoType changeVideoType = new ChangeVideoType();
			changeVideoType.show();
			primaryStage.close();
		});
		Pane btnMerge = new Pane();
		ImageView mergeimageView = new ImageView(new Image("res/image/stage/merge.png"));
		mergeimageView.setLayoutX(25);
		btnMerge.setLayoutX(600);
		btnMerge.setLayoutY(130);
		btnMerge.setStyle(style);
		btnMerge.setPrefSize(180, 165);

		Label lblmerge = new Label("合并视频");
		lblmerge.setTextFill(Color.WHITE);
		lblmerge.setFont(Font.font("KaiTi", 28));
		lblmerge.setLayoutX(35);
		lblmerge.setLayoutY(125);

		btnMerge.getChildren().add(mergeimageView);
		btnMerge.getChildren().add(lblmerge);

		btnMerge.setOnMouseEntered(e -> {
			btnMerge.setStyle("-fx-border-color:#fff;-fx-border-width:1px");
		});

		btnMerge.setOnMouseExited(e -> {
			btnMerge.setStyle("-fx-border-width:0px");
		});

		btnMerge.setOnMouseClicked(e->{
			MergeVideo mergeVideo=new MergeVideo();
			mergeVideo.show();
			primaryStage.close();
			
		});
		pane.getChildren().add(btnClose);
		pane.getChildren().add(btnHide);
		pane.getChildren().add(line);
		pane.getChildren().add(btnRecordVideo);
		pane.getChildren().add(btnRecordAudio);
		pane.getChildren().add(btnChangeType);
		pane.getChildren().add(btnMerge);

		// 窗口拖动
		primaryStage.addEventHandler(MouseEvent.ANY, new EventHandler<MouseEvent>() {

			@Override
			public void handle(MouseEvent event) {
				// TODO Auto-generated method stub
				event.consume();
				if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
					xOffset = event.getSceneX();
					yOffset = event.getSceneY();
				} else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
					primaryStage.setX(event.getScreenX() - xOffset);
					if (event.getScreenY() - yOffset < 0) {
						primaryStage.setY(0);
					} else {
						primaryStage.setY(event.getScreenY() - yOffset);
					}
				}
			}
		});
		primaryStage.getIcons().add(new Image("res/image/stage/logo.png"));
		Scene scene = new Scene(pane);
		primaryStage.setScene(scene);
		primaryStage.initStyle(StageStyle.UNDECORATED);// 设定窗口无边框
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}

}
